﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Kiiro.Common.Interfaces;

namespace Kiiro.Common.Entities
{
    [Serializable]
    public class Document : BaseEntity, IEntity
    {
        #region Private Properties

        private byte[] fileBytes;
        private long fileLength;
        private List<ValidationMessage> fileMessage = new List<ValidationMessage> ( );
        private string folderUrl;
        private bool isFolder;
        private string iconUrl;
        private int version;
        private string versionLabel;
        private string url;
        private int contains;
        private bool isProjectPlan = false;

        private bool isCreatedThisWeekAdd;
        private bool isUpdatedThisWeekAdd;

        #endregion

        #region Public Properties

        public byte[] FileBytes
        {
            get { return fileBytes; }
            set { fileBytes = value; }
        }

        public long FileLength
        {
            get { return fileLength; }
            set { fileLength = value; }
        }
        
        public List<ValidationMessage> FileMessage
        {
            get { return fileMessage; }
            set
            {
                if ( fileMessage != value )
                {
                    fileMessage = value;
                    UpdateEntity ( );
                }
            }
        }

        public string FolderUrl
        {
            get { return folderUrl; }
            set { folderUrl = value; }
        }

        public bool IsFolder
        {
            get { return isFolder; }
            set { isFolder = value; }
        }

        public string IconUrl
        {
            get { return iconUrl; }
            set { iconUrl = value; }
        }

        public int Version
        {
            get { return version; }
            set { version = value; }
        }

        public string VersionLabel
        {
            get { return versionLabel; }
            set { versionLabel = value; }
        }

        public string Url
        {
            get { return url; }
            set { url = value; }
        }

        public int Contains
        {
            get { return contains; }
            set { contains = value; }
        }

        /// <summary>
        /// Indicates that the document is the Project Plan File for the current project site
        /// </summary>
        public bool IsProjectPlan
        {
            get { return isProjectPlan; }
            set { isProjectPlan = value; }
        }

        /// <summary>
        /// Indicates that the document has already been added to the statistics as created this week
        /// </summary>
        public bool IsCreatedThisWeekAdd
        {
            get { return isCreatedThisWeekAdd; }
            set { isCreatedThisWeekAdd = value; }
        }

        /// <summary>
        /// Indicates that the document has already been added to the statistics as updated this week
        /// </summary>
        public bool IsUpdatedThisWeekAdd
        {
            get { return isUpdatedThisWeekAdd; }
            set { isUpdatedThisWeekAdd = value; }
        }

        #endregion

        #region IEntity Members


        public new bool IsValid()
        {
            return AllValidationErrors().Count == 0;
        }

        public new List<ValidationMessage> AllValidationErrors()
        {
            List<ValidationMessage> allErrors = new List<ValidationMessage>();

            allErrors.AddRange(TitleMessage);
            allErrors.AddRange ( DescriptionMessage );
            allErrors.AddRange ( FileMessage );

            return allErrors;
        }

        public new void ClearValidationMessages()
        {
            TitleMessage.Clear();
            FileMessage.Clear ( );
            DescriptionMessage.Clear ( );
        }

        #endregion

        public static bool RecentlyUpdated(Document document)
        {
            return document.ModifiedDate >= DateTime.Now.AddDays(-7);
        }
    }
}

/*************************************************************************
 * 
 * $Log: /Internal Projects/Kiiro/Kiiro.Common/Entities/Document.cs $
 * 
 * 4     10/27/09 1:52p Adamw
 * added IsProjectPlan property
 * 
 * 3     17/08/09 10:38a Camerons
 * Added check-in comments section
 * 
 ************************************************************************/